﻿/****************************************************
// 功能：技能替换Buff
// | Talk To [ 聊来改善地区金融服务环境，助力企业发展 ]
// | Copyright (c) 2021-2025 聊来 All rights reserved.
// | Licensed ( <a href="http://www.apache.org/licenses/LICENSE-2.0">聊来</a> )
// | @Author: 贯彻己道的云 <18970881148@qq.com>
// | DateTime: 2025/4/9 11:37:01
*****************************************************/
public class CommonModifySkillBuffCfg : BuffCfg {
    public int originalID;
    public int replaceID;
}

public class CommonModifySkillBuff : Buff {
    public int originalID;
    public int replaceID;
    private Skill modifySkill;

    public CommonModifySkillBuff(MainLogicUnit source, MainLogicUnit owner, Skill skill, int buffID, object[] args = null)
        : base(source, owner, skill, buffID, args) {
    }

    public override void LogicInit() {
        base.LogicInit();

        var mabc = cfg as CommonModifySkillBuffCfg;
        originalID = mabc!.originalID;
        replaceID = mabc.replaceID;
        modifySkill = owner.GetSkillById(originalID);
    }

    protected override void Start() {
        base.Start();

        modifySkill.ReplaceSkillCfg(replaceID);
        modifySkill.SpellSuccessCallback += ReplaceSkillReleaseDone;
    }

    void ReplaceSkillReleaseDone(Skill skillReleased) {
        if(skillReleased.config.isNormalAttack) {
            unitState = SubUnitState.End;
        }
    }

    protected override void End() {
        base.End();
        modifySkill.ReplaceSkillCfg(originalID);
        modifySkill.SpellSuccessCallback -= ReplaceSkillReleaseDone;
    }
}
